import { Sequelize, DataTypes, Model } from 'sequelize';

export interface TodoListAttributes {
  id?: number;
  title: string;
  desc: string;
}

export class TodoList extends Model<TodoListAttributes> implements TodoListAttributes {
  public id!: number;
  public title!: string;
  public desc!: string;

  public readonly createdAt!: Date;
  public readonly updatedAt!: Date;
}

export const sequelize = new Sequelize({
  dialect: 'sqlite',
  storage: ':memory:'
});

TodoList.init(
  {
    title: {
      type: DataTypes.STRING,
      allowNull: false
    },
    desc: {
      type: DataTypes.STRING,
      allowNull: false
    }
  },
  {
    sequelize,
    modelName: 'TodoList'
  }
);